package com.example.login

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.lib_data.bmob.UserManager

class LgLoginViewModel : ViewModel(){
    private val mUserManager = UserManager.getInstance()
    val phoneNumber:MutableLiveData<String> = MutableLiveData("18502332377")//TODO  测试完毕需要设为空
    var isChecked = MutableLiveData(false)   //TODO true为测试所用
    val agreementShouldSwing = MutableLiveData(false)
    var time = 59  //发送验证码倒计时
    fun clearPhoneNumber(){
        phoneNumber.postValue("")
    }

    /***
     * 请求发送验证码
     */
    fun requestSms(onStart:()->Unit={}, onEnd:(Boolean)->Unit = {}){
        mUserManager.requestSms(phoneNumber.value!!, onStart = {onStart()}, onEnd = {onEnd(it)})
    }

    /**
     * 验证码一键注册和登录
     */
    fun verifyAndLogin(code:String,  onEnd:(Boolean)->Unit = {}){
        mUserManager.loginBySmsCode(phoneNumber.value!!,code, onEnd = onEnd)
    }

    /**
     * 密码登录
     */
    fun loginByPassword(password:String,onStart:()->Unit={}, onEnd:(Boolean)->Unit = {} ){
        mUserManager.loginByPhone(phoneNumber.value!!,password, onStart, onEnd)
    }
}














